package com.morehair.service.wx.impl;

import com.morehair.bean.pojo.Category;
import com.morehair.bean.pojo.CategoryExample;
import com.morehair.bean.vo.wx.WxCataLogVo;
import com.morehair.mapper.CategoryMapper;
import com.morehair.service.wx.WxCataLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author  kkw
 * Date  2021/6/9 10:13
 * Version 1.0
 * Description :
 */
@Service
public class WxCataLogServiceImpl implements WxCataLogService {
    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public WxCataLogVo getCategory() {
        CategoryExample categoryExample = new CategoryExample();
        categoryExample.setOrderByClause("sort_order asc");
        CategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andLevelEqualTo("L1").andDeletedEqualTo(false);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        WxCataLogVo wxCataLogVo = new WxCataLogVo();
        wxCataLogVo.setCurrentCategory(categories.get(0));
        wxCataLogVo.setCategoryList(categories);

        return wxCataLogVo;
    }

    @Override
    public WxCataLogVo getSubCategory(Integer id) {
        WxCataLogVo wxCataLogVo = new WxCataLogVo();
        Category category = categoryMapper.selectByPrimaryKey(id);
        wxCataLogVo.setCurrentCategory(category);
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andDeletedEqualTo(false).andPidEqualTo(id);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        wxCataLogVo.setCurrentSubCategory(categories);
        return wxCataLogVo;
    }
}
